package com.zxs.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zxs.infra.basic.entity.SubjectRadio;
import com.zxs.infra.basic.mapper.SubjectRadioMapper;
import com.zxs.infra.basic.service.SubjectRadioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 单选题选项表(SubjectRadio)表服务实现类
 *
 * @author makejava
 * @since 2025-11-12 21:06:02
 */
@Service
public class SubjectRadioServiceImpl implements SubjectRadioService {
    @Autowired
    private SubjectRadioMapper subjectRadioMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectRadio queryById(Integer id) {
        return this.subjectRadioMapper.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param subjectRadio 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectRadio insert(SubjectRadio subjectRadio) {
        this.subjectRadioMapper.insert(subjectRadio);
        return subjectRadio;
    }

    /**
     * 修改数据
     *
     * @param subjectRadio 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectRadio update(SubjectRadio subjectRadio) {
        this.subjectRadioMapper.update(subjectRadio);
        return this.queryById(subjectRadio.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.subjectRadioMapper.deleteById(id) > 0;
    }

    @Override
    public Integer batchInsert(List<SubjectRadio> subjectRadios) {
        //批量插入
        return subjectRadioMapper.insertBatch(subjectRadios);
    }

    @Override
    public SubjectRadio queryBySubjectId(int subjectId) {

        LambdaQueryWrapper<SubjectRadio> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SubjectRadio::getSubjectId, subjectId)
                .eq(SubjectRadio::getIsCorrect, 1);
        SubjectRadio subjectRadio = subjectRadioMapper.selectOne(queryWrapper);
        return subjectRadio;
    }
}
